<template>
  <div class="infrastructure-introduce-container page-common-layout">
    <div class="hazard-body-container">
      <div class="operate">
        基建板块介绍
      </div>
      <div class="main">
        <vxe-table
          ref="xTable"
          height="99%"
          align="center"
          show-overflow
          show-header-overflow
          border="inner"
          :data="tableData"
          :column-config="{ resizable: true }"
          size="small"
          :loading="loading"
        >
          <vxe-column type="seq" width="80" title="序号"></vxe-column>
          <vxe-column field="orgName" title="名称"> </vxe-column>
          <vxe-column field="orgEnterpriseTypeDesc" title="类型"> </vxe-column>
          <vxe-column field="modifier" title="编辑人"> </vxe-column>
          <vxe-column field="modifyTime" title="编辑时间"> </vxe-column>
          <vxe-column
            field="operate"
            width="80"
            title="操作"
            fixed="right"
            align="left"
          >
            <template #default="{ row }">
              <div class="text-button-group">
                <a-button type="link" @click="editor(row)" v-action:jjbkpz_edit>
                  编辑
                </a-button>
              </div>
            </template>
          </vxe-column>
        </vxe-table>
      </div>
    </div>
    <!-- 编辑弹窗-->
    <edit-form
      ref="createModal"
      :visible="visible"
      :loading="confirmLoading"
      :url="url"
      requestMethod="post"
      :tableDataType="tableDataType"
      @cancel="handleCancel()"
      @ok="handleOk()"
    />
  </div>
</template>

<script>
import editForm from "@/pages/form/formPreview/edit.vue";
import { axios } from "@/utils/request";
export default {
  components: {
    editForm,
  },
  data() {
    return {
      loading: false,
      tableData: [],
      //
      visible: false,
      confirmLoading: false,
      url: {
        update: "/form/formDatabase/formUpdate",
      },
      tableDataType: "",
      tableUuid: "CF2C40131D1D4F46B8BD38C24FA08730",
    };
  },
  mounted() {
    this.getData();
  },
  methods: {
    handleClick() {
      this.$router.push({
        path: "/projectHome",
      });
    },
    //查询列表数据
    getData() {
      axios
        .post(
          "/mdata/organization/getEnterpriseCompanyList",
          {
            body: {},
          },
          {
            headers: {
              "Content-Type": "application/json",
            },
          }
        )
        .then((res) => {
          let { data } = res;
          this.tableData = data;
        })
        .catch((_) => {
          this.tableData = [];
        });
    },
    //编辑
    async editor(record = {}) {
      let { orgEnterpriseType, uuid } = record;
      if (orgEnterpriseType == "EnterpriseType.01") {
        this.tableUuid = "444F39AA38E14D46A01602E066FFFBB5";
      } else {
        this.tableUuid =
          process.env.VUE_APP_API_BASE_URL == "http://10.107.32.158:20004"
            ? "B5136A52289A45DB941CE7D6512758F0"
            : "CF2C40131D1D4F46B8BD38C24FA08730";
      }
      this.visible = true;
      let formJsonData = await this.loadDataJson();
      this.$refs.createModal.title = "编辑";
      this.$refs.createModal.loading = true;
      this.$post("/form/formDatabase/formGetDetail", {
        uuid: uuid,
        formUuid: this.tableUuid,
      }).then((res) => {
        this.$refs.createModal.loadData(
          this.tableUuid,
          "edit",
          formJsonData,
          res
        );
        this.getData();
      });
    },

    loadDataJson() {
      return new Promise((reslove) => {
        this.$post("/form/formBasicConfigure/getDetailByUuid", {
          uuid: this.tableUuid,
        })
          .then((res) => {
            this.tableDataType = res.formDatabase?.type || "";
            reslove(res.formDesign.designJson);
          })
          .catch((_) => {
            reslove({});
          });
      });
    },

    //关闭弹窗
    handleCancel() {
      this.visible = false;
    },

    handleOk() {
      this.getData();
      this.visible = false;
    },
  },
};
</script>

<style lang="less" scoped>
.infrastructure-introduce-container {
  display: flex;
  flex-direction: column;
  .hazard-body-container {
    flex: 1;
    background-color: @base-bg-color;
    flex-shrink: 0;
    position: relative;
    padding: 10px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    .operate {
      display: flex;
      color: #333333;
      font-size: 16px;
      padding: 10px 0 20px 0;
      font-weight: bold;
    }
    .main {
      flex: 1;
    }
    .pager-container {
      flex-shrink: 0;
      box-sizing: border-box;
    }
  }
}
</style>
